﻿using System.Web;
using System.Threading;
using System.Data.SqlClient;
using Sissonix.ExtRest.WADL;

namespace Sissonix.ExtRest.RestManager.Processors
{
    class DBTestProcessor : BaseRestProcessor
    {
        public DBTestProcessor()
        {
        }

        public new void ProcessRequest(WADLContext context)
        {
            base.ProcessRequest(context);
        }


        /*Get is for Retrievals*/
        public override void ProcessGet(WADLContext context)
        {
            HttpRequest req = HttpContext.Current.Request;

            string db = req.Params["sqlServerDbName"];
            string server = req.Params["sqlServer"];
            string user = req.Params["sqlServerUser"];
            string pass = req.Params["sqlServerPassword"];
            Thread.Sleep(500);

            try
            {
                string constr = string.Format("user id={0};password={1};server={2};database={3};Trusted_Connection=yes;",
                    user, pass, server, db);
                
                SqlConnection myConnection = new SqlConnection(constr);
                
                myConnection.Open();
                
                HttpContext.Current.Response.Write(@"{""success"": true}");
            }
            catch (System.Exception e)
            {
                    HttpContext.Current.Response.Write(@"{""success"": false}");
            }


        }
    }
}